package ScalaStudy.chapter06

object Test17_Extends {
  def main(args: Array[String]): Unit = {


    /////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////   特质自身类型  /////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////


    val student: Student17 = new Student17("wq", 27)
    student.study()
    student.sayHi()

    val person: Person17 = new Student17("wq", 27) //调用的是子类，而类型是父类
    person.sayHi()
//    person.study()                                             //如果类型是父类，则不能调用子类的方法

    //类型判断
    println("student is Student17: " + student.isInstanceOf[Student17])
    println("student is Person17: " + student.isInstanceOf[Person17])
    println("person  is Person17: " + person.isInstanceOf[Person17])
    println("person  is Student17: " + person.isInstanceOf[Student17])

    val person2: Person17 = new Person17("wq",27)                  //父类的对象不能认为是子类的类型
    println("person2  is Student17: " + person2.isInstanceOf[Student17])


    //类型转换
    if (person.isInstanceOf[Student17]){                                       //如果把父类装换成子类
      val newStudent = person.asInstanceOf[Student17]
      newStudent.study()
    }

    //查看类名
    println(classOf[Student17])                                                //查看对象的类名

    println("====================    测试枚举类    ============================")
    println(WorkDay.MONDAY)

  }
}


class Person17 (val name:String, val age: Int){
  def sayHi(): Unit = {
    println("hi from persion" + name)
  }
}

class Student17 ( name:String, age: Int) extends Person17(name:String, age: Int){
  override def sayHi(): Unit = {
    println("打招呼学生的名字:" + name)
  }
  def study(): Unit = {
    println("开始学习")
  }
}


    /////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////   枚举类和应用类 /////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////

//枚举类定义

object WorkDay extends Enumeration{
  val MONDAY = Value(1, "Monday")
  val TUESDAY = Value(2, "Tuesday")
}

//应用类定义

object TestAPP extends App{         //点击这个箭头
  println("app start")

  //给类换名字
  type MyString = String
  val a: MyString = "abc"
  println(a)


}